// Copyright (C) 2003 IFOnlyRT Project.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License 2.0 for more details.

// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

// Official SVN repository and contact information can be found at
// http://code.google.com/p/ifonlyrt/

#include <iostream>

#include "../../Basics/CVector2.tpp"
#include "ErrorHandler.hpp"

int CVector2_TestAll();
int CVector2_TestStaticsMembers();
int CVector2_TestConstructors();
int CVector2_TestPublicMethods();
int CVector2_TestStaticMethods();

using namespace std;

int CVector2_TestAll()
{
	cout << "::CVector2 - Début des tests ..." << endl;

	if(CVector2_TestStaticsMembers() != 0) return ThrowError("	::CVector2 - Erreur dans le test des membres statiques !");
	if(CVector2_TestConstructors() != 0) return ThrowError("	::CVector2 - Erreur dans le test des constructeurs !");
	if(CVector2_TestPublicMethods() != 0) return ThrowError("	::CVector2 - Erreur dans le test des méthodes publiques !");
	if(CVector2_TestStaticMethods() != 0) return ThrowError("	::CVector2 - Erreur dans le test des méthodes statiques !");

	cout << "::CVector2 - OK" << endl << endl;

	return 0;
}

int CVector2_TestStaticsMembers()
{
	cout << "	::CVector2 - Test des membres statiques..." << endl;

	if(CVector2<double>::Zero != CVector2<double>(0, 0)) return -1;
	if(CVector2<double>::One != CVector2<double>(1, 1)) return -1;

	cout << "	::CVector2 - Membres statiques : OK" << endl;

	return 0;
}

int CVector2_TestConstructors()
{
	cout << "	::CVector2 - Test des constructeurs..." << endl;

	CVector2<double> V;
	if(V.X != 0 || V.Y != 0) return -1;

	V = CVector2<double>(1, 2);
	if(V.X != 1 || V.Y != 2) return -1;

	V = CVector2<double>(666);//!!!!
	if(V.X != 666 || V.Y != 666) return -1;

	CVector2<double> V2(V);
	if(V2.X != 666 || V2.Y != 666) return -1;

	cout << "	::CVector2 - Constructeurs : OK" << endl;

	return 0;
}

int CVector2_TestPublicMethods()
{
	cout << "	::CVector2 - Test des méthodes publiques..." << endl;

	CVector2<double> V(2, 2);

	if(V.GetModulus() != sqrt(2*4)) return -1;
	if(V.GetSquaredModulus() != 2*4) return -1;

	CVector2<double> V2 = V.GetNormalized();
	if(V2.X != 2.0 / sqrt(2*4) || V2.Y != 2.0 / sqrt(2*4)) return -1;

	V.Normalize();
	if(V != V2) return -1;

	cout << "	::CVector2 - Méthodes publiques : OK" << endl;

	return 0;
}


int CVector2_TestStaticMethods()
{
	cout << "	::CVector2 - Test des méthodes statiques..." << endl;

	CVector2<double> V(2, 2);

	if(CVector2<double>::Dot(V,V) != V.GetSquaredModulus()) return -1;

	cout << "	::CVector2 - Méthodes statiques : OK" << endl;

	return 0;
}
